<?php
/**
 * shopify订单
 * (shopify-model)
 */
namespace App\Models\Shopify;

use Illuminate\Database\Eloquent\Model;

class ShopifyOrder extends Model
{
    protected $connection = 'mysql_shopify';

    protected $table = 'shopify_orders';

    protected $guarded  = [];

    /**
     * 订单状态
     * @var string[]
     */
    const SYNC_NO = 1; //未同步
    const SYNC_YES = 2; //已同步
    const SYNC_ERROR = 3; //同步异常
    public static $_erpSync = [
        1 => '未同步',
        2 => '已同步',
        3 => '同步异常',
    ];

    public function shopify_orders_items(){
        return $this->hasMany(ShopifyOrderItem::class, 'order_id', 'order_id');
    }

    public function shopify_orders_lines(){
        return $this->hasMany(ShopifyOrderLines::class, 'order_id', 'order_id');
    }

    public function shopify_orders_address(){
        return $this->hasOne(ShopifyOrderAddress::class, 'order_id', 'order_id');
    }


    public static function getModelById($id){
        return self::query()->find($id);
    }

    public static function getValueById($id,$field){
        return self::query()->where('id',$id)->value($field);
    }

    public static function getModelByCode($orderId){
        return self::query()->where('order_id',$orderId)->first();
    }

    public static function getValueByCode($orderId,$field){
        return self::query()->where('order_id',$orderId)->value($field);
    }

}
